package com.example.ovulationperiodtracker.Allactivity;

import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.example.ovulationperiodtracker.databinding.ActivityPinInsertBinding;
import com.example.ovulationperiodtracker.utils.JCGSQLiteHelper;
import com.example.ovulationperiodtracker.R;
import com.example.ovulationperiodtracker.model.User;
import com.example.ovulationperiodtracker.view.NoteUtils;
import com.necer.base.BaseActivity;

import me.philio.pinentry.PinEntryView;

public class PinInsertActivity extends BaseActivity<ActivityPinInsertBinding> {


    @Override
    protected ActivityPinInsertBinding createBinding(LayoutInflater inflater) {
        return ActivityPinInsertBinding.inflate(inflater);
    }

    @Override
    protected void onCreated(Bundle savedInstanceState) {

        String password = NoteUtils.getPin();

        if (password.equals("")) {
            binding.llPin.setVisibility(View.INVISIBLE);
            binding.PinSwitch.setChecked(false);
        } else {
            binding.llPin.setVisibility(View.VISIBLE);
            binding.PinSwitch.setChecked(true);
        }
        binding.PinSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton compoundButton, boolean bChecked) {
                if (bChecked) {
                    binding.llPin.setVisibility(View.VISIBLE);
                } else {
                    binding.llPin.setVisibility(View.INVISIBLE);
                    NoteUtils.savePin("");
                }
            }
        });
        binding.btnSave.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (binding.pinEntrySimple.getText().toString().trim().length() < 4 || binding.pinEntryConfirm.getText().toString().trim().length() < 4) {
                    Toast toast = Toast.makeText(PinInsertActivity.this, getString(R.string.toast_dialog_corti), Toast.LENGTH_SHORT);
                    toast.setGravity(17, 0, 0);
                    toast.show();
                    return;

                }
                if (!binding.pinEntrySimple.getText().toString().equals(binding.pinEntryConfirm.getText().toString())) {
                    Toast toast2 = Toast.makeText(PinInsertActivity.this, getString(R.string.toast_dialog_diff), Toast.LENGTH_SHORT);
                    toast2.setGravity(17, 0, 0);
                    toast2.show();
                    return;
                }

                NoteUtils.savePin(binding.pinEntrySimple.getText().toString());
                finish();
            }
        });
    }

}
